package fnord.illuminati.card.winconditions;

import java.util.Arrays;
import java.util.Collection;
import java.util.LinkedList;
import java.util.Queue;

import fnord.illuminati.card.Alignment;
import fnord.illuminati.card.GroupCard;
import fnord.illuminati.card.WinCondition;
import fnord.network.server.Player;

public class BermudaWinCondition extends WinCondition {
	private static final long serialVersionUID = -4743163336666656863L;
	
	@Override
	public boolean hasWon(Player p) {
		Queue<GroupCard> cards = new LinkedList<GroupCard>();
		cards.add(p.getIlluminati());
		Collection<Alignment> alignments = Alignment.getAll();
		
		while (!cards.isEmpty()&&!alignments.isEmpty()) {
			GroupCard current = cards.poll();
			cards.addAll(current.getChildren());
			alignments.removeAll(Arrays.asList(current.getAlignments()));
		}
		
		if (alignments.isEmpty())
			return true;
		else
			return false;
	}

}
